<template>
  <!--  单选按钮-->
  <el-radio-group  v-model="localValue">
    <el-radio
      :disabled="config.disabled||false"
      v-for="(item,index) in options"
      :key="index"
      :label="item[config.defaultProps.value]"
    >{{ item[config.defaultProps.label] }}
    </el-radio>
  </el-radio-group>
</template>

<script>
import {postAction} from "@rule/api/rule/manage/instance";

export default {
  name: "config-radio",
  props: {
    value: String,
    config: {
      type: Object,
      default: {}
    },
  },

  data() {
    return {
      options: []
    }
  },
  computed: {
    localValue: {
      get() {
        return this.value;
      },
      set(newValue) {
        // 这里可以调用一个方法来通知父组件值已更改
        this.$emit('updateValue', newValue);
      }
    }
  },
  watch: {
    'config.path': {
      immediate: true,
      // deep: true,
      handler(val) {
        postAction(val, this.config.extraForm || {}).then(
          response => {
            this.$set(this.config, 'defaultProps', {
              label: 'dictLabel',
              value: 'dictValue',
            });
            this.$emit('setOptions', response.data);
            this.options = response.data;
            // this.value = data.value || '';
          });
      }
    },
  },
  methods:{
    // updateValue(value) {
    //   this.$emit('updateValue', value);
    // },
  }
}
</script>

<style scoped>

</style>
